package lgq.servlet;


import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import lgq.service.CourseManager;
import lgq.service.EmpManager;
import lgq.service.TeacherManager;
import lgq.service.TrainManager;
import lgq.service.TrainPropertyManager;
import lgq.service.TrainTypeManager;
import lgq.service.TrainWayManager;
import model.Course;
import model.Teacher;
import model.Train;
import model.TrainCourse;

public class UpdateTrainServlet extends HttpServlet {
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		this.doPost(request, response);
	}
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {		
		Train train=new Train();
		train.setId(Integer.parseInt(request.getParameter("trainid")));
		train.setTrainname(request.getParameter("trainname"));
		train.setAddress(request.getParameter("address"));
		train.setMoney(Double.parseDouble(request.getParameter("money")));
		train.setOrganization(request.getParameter("organization"));
		TrainTypeManager ttm=new TrainTypeManager();		
		train.setTrainType(ttm.getById(Integer.parseInt(request.getParameter("traintype"))));
		TrainPropertyManager tpm=new TrainPropertyManager();
		train.setTrainProperty(tpm.getById(Integer.parseInt(request.getParameter("trainProperty"))));
		TrainWayManager twm=new TrainWayManager();
		train.setTrainWay(twm.getById(Integer.parseInt(request.getParameter("trainWay"))));
		try {
			train.setStarttime(new SimpleDateFormat("yyyy-MM-dd").parse(request.getParameter("starttime")));
			train.setEndtime(new SimpleDateFormat("yyyy-MM-dd").parse(request.getParameter("endtime")));
		} catch (ParseException e) {
			e.printStackTrace();
		}
		TrainManager tm=new TrainManager();
		tm.updateTrain(train);
		request.getRequestDispatcher("/FindTrainServlet").forward(request,response);
	}


}
